package com.lzy.product.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lzy.framework.core.orm.db.Pager;
import com.lzy.framework.core.utils.DozerUtils;
import com.lzy.product.common.util.UserUtil;
import com.lzy.product.dao.ProductSaleLevelMapperExt;
import com.lzy.product.dtos.ProductSaleLevelDto;
import com.lzy.product.entity.ProductSaleLevel;
import com.lzy.product.service.ProductSaleLevelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by WIN7 on 2017/12/11.
 */
@Service
public class ProductSaleLevelServiceImpl implements ProductSaleLevelService {

    @Autowired
    ProductSaleLevelMapperExt productSaleLevelMapperExt;

    @Override
    public Long insert(ProductSaleLevelDto dto) {
        ProductSaleLevel productSaleLevel = DozerUtils.map(dto, ProductSaleLevel.class);
        return productSaleLevelMapperExt.insertSelective(productSaleLevel) > 0 ? productSaleLevel.getId() : null;
    }

    @Override
    public Boolean update(ProductSaleLevelDto dto) {
        return productSaleLevelMapperExt.updateByPrimaryKeySelective(DozerUtils.map(dto, ProductSaleLevel.class)) > 0;
    }

    @Override
    public Boolean delete(Long id) {
        return productSaleLevelMapperExt.deleteByPrimaryKey(id) > 0;
    }

    @Override
    public Boolean remove(Long id) {
        return productSaleLevelMapperExt.remove(id, UserUtil.getCurrentUser().getId()) > 0;
    }

    @Override
    public ProductSaleLevelDto findById(Long id) {
        return DozerUtils.map(productSaleLevelMapperExt.selectByPrimaryKey(id), ProductSaleLevelDto.class);
    }

    @Override
    public List<ProductSaleLevelDto> query(ProductSaleLevelDto dto) {
        return productSaleLevelMapperExt.selectList(dto);
    }

    @Override
    public PageInfo<ProductSaleLevelDto> selectList(Pager pager, ProductSaleLevelDto dto) {
        if (pager != null)
            PageHelper.startPage(pager.getPageNum(), pager.getPageSize());
        return new PageInfo<>(productSaleLevelMapperExt.selectList(dto));
    }

    @Override
    public Integer updateList(String ids) {
        return productSaleLevelMapperExt.updateList(ids, UserUtil.getCurrentUser().getId());
    }
}
